<html>
<head>
  <title>../ex5b77.f</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<a href="../ex5b77.f">download the original source code</a>.
<pre>
<a name="line1">  1</a> <font color="#444444">c</font>
<a name="line2">  2</a> <font color="#444444">c   Example 5</font>
<a name="line3">  3</a> <font color="#444444">c</font>
<a name="line4">  4</a> <font color="#444444">c   Interface:    Linear-Algebraic (IJ), Babel-based version in Fortran</font>
<a name="line5">  5</a> <font color="#444444">c</font>
<a name="line6">  6</a> <font color="#444444">c   Compile with: make ex5b</font>
<a name="line7">  7</a> <font color="#444444">c</font>
<a name="line8">  8</a> <font color="#444444">c   Sample run:   mpirun -np 4 ex5b</font>
<a name="line9">  9</a> <font color="#444444">c</font>
<a name="line10"> 10</a> <font color="#444444">c   Description:  This example solves the 2-D</font>
<a name="line11"> 11</a> <font color="#444444">c                 Laplacian problem with zero boundary conditions</font>
<a name="line12"> 12</a> <font color="#444444">c                 on an nxn grid.  The number of unknowns is N=n^2.</font>
<a name="line13"> 13</a> <font color="#444444">c                 The standard 5-point stencil is used, and we solve</font>
<a name="line14"> 14</a> <font color="#444444">c                 for the interior nodes only.</font>
<a name="line15"> 15</a> <font color="#444444">c</font>
<a name="line16"> 16</a> <font color="#444444">c                 This example solves the same problem as Example 3.</font>
<a name="line17"> 17</a> <font color="#444444">c                 Available solvers are AMG, PCG, and PCG with AMG or</font>
<a name="line18"> 18</a> <font color="#444444">c                 Parasails preconditioners.</font>
<a name="line19"> 19</a> 
<a name="line20"> 20</a>       <strong>program</strong> <font color="#2040a0">ex5b77</font>
<a name="line21"> 21</a> 
<a name="line22"> 22</a> 
<a name="line23"> 23</a>       <strong>implicit</strong> <strong>none</strong>
<a name="line24"> 24</a> 
<a name="line25"> 25</a>       <strong>include</strong> '<font color="#2040a0">mpif</font>.<font color="#2040a0">h</font>'
<a name="line26"> 26</a> 
<a name="line27"> 27</a>       <strong>integer</strong>    <font color="#2040a0">MAX_LOCAL_SIZE</font>
<a name="line28"> 28</a>       <strong>parameter</strong>  <font color="4444FF">(</font><font color="#2040a0">MAX_LOCAL_SIZE</font><font color="4444FF">=</font><font color="#FF0000">123000</font><font color="4444FF">)</font>
<a name="line29"> 29</a> 
<a name="line30"> 30</a>       <strong>integer</strong>    <font color="#2040a0">ierr</font>, <font color="#2040a0">ierrtmp</font>
<a name="line31"> 31</a>       <strong>integer</strong>    <font color="#2040a0">num_procs</font>, <font color="#2040a0">myid</font>
<a name="line32"> 32</a>       <strong>integer</strong>    <font color="#2040a0">local_size</font>, <font color="#2040a0">extra</font>
<a name="line33"> 33</a>       <strong>integer</strong>    <font color="#2040a0">n</font>, <font color="#2040a0">solver_id</font>, <font color="#2040a0">print_solution</font>, <font color="#2040a0">ng</font>
<a name="line34"> 34</a>       <strong>integer</strong>    <font color="#2040a0">nnz</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">i</font>
<a name="line35"> 35</a>       <strong>double precision</strong> <font color="#2040a0">h</font>, <font color="#2040a0">h2</font>
<a name="line36"> 36</a>       <strong>double precision</strong> <font color="#2040a0">rhs_values</font><font color="4444FF">(</font><font color="#2040a0">MAX_LOCAL_SIZE</font><font color="4444FF">)</font>
<a name="line37"> 37</a>       <strong>double precision</strong> <font color="#2040a0">x_values</font><font color="4444FF">(</font><font color="#2040a0">MAX_LOCAL_SIZE</font><font color="4444FF">)</font>
<a name="line38"> 38</a>       <strong>integer</strong>    <font color="#2040a0">rows</font><font color="4444FF">(</font><font color="#2040a0">MAX_LOCAL_SIZE</font><font color="4444FF">)</font>
<a name="line39"> 39</a>       <strong>integer</strong>    <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#FF0000">5</font><font color="4444FF">)</font>
<a name="line40"> 40</a>       <strong>double precision</strong> <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#FF0000">5</font><font color="4444FF">)</font>
<a name="line41"> 41</a>       <strong>integer</strong>    <font color="#2040a0">num_iterations</font>
<a name="line42"> 42</a>       <strong>double precision</strong> <font color="#2040a0">final_res_norm</font>, <font color="#2040a0">tol</font>
<a name="line43"> 43</a> 
<a name="line44"> 44</a>       <strong>integer*8</strong>  <font color="#2040a0">bHYPRE_mpicomm</font>
<a name="line45"> 45</a>       <strong>integer*8</strong>  <font color="#2040a0">mpi_comm</font>
<a name="line46"> 46</a>       <strong>integer*8</strong>  <font color="#2040a0">parcsr_A</font>
<a name="line47"> 47</a>       <strong>integer*8</strong>  <font color="#2040a0">op_A</font>
<a name="line48"> 48</a>       <strong>integer*8</strong>  <font color="#2040a0">par_b</font>
<a name="line49"> 49</a>       <strong>integer*8</strong>  <font color="#2040a0">par_x</font>
<a name="line50"> 50</a>       <strong>integer*8</strong>  <font color="#2040a0">vec_b</font>
<a name="line51"> 51</a>       <strong>integer*8</strong>  <font color="#2040a0">vec_x</font>
<a name="line52"> 52</a>       <strong>integer*8</strong>  <font color="#2040a0">amg_solver</font>
<a name="line53"> 53</a>       <strong>integer*8</strong>  <font color="#2040a0">except</font>
<a name="line54"> 54</a> <font color="#444444">c     ... except is for Babel exceptions, which we shall ignore</font>
<a name="line55"> 55</a> 
<a name="line56"> 56</a> <font color="#444444">c-----------------------------------------------------------------------</font>
<a name="line57"> 57</a> <font color="#444444">c     Initialize MPI</font>
<a name="line58"> 58</a> <font color="#444444">c-----------------------------------------------------------------------</font>
<a name="line59"> 59</a> 
<a name="line60"> 60</a>       <strong>call</strong> <font color="#2040a0">MPI_INIT</font><font color="4444FF">(</font><font color="#2040a0">ierr</font><font color="4444FF">)</font>
<a name="line61"> 61</a>       <strong>call</strong> <font color="#2040a0">MPI_COMM_RANK</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">myid</font>, <font color="#2040a0">ierr</font><font color="4444FF">)</font>
<a name="line62"> 62</a>       <strong>call</strong> <font color="#2040a0">MPI_COMM_SIZE</font><font color="4444FF">(</font><font color="#2040a0">MPI_COMM_WORLD</font>, <font color="#2040a0">num_procs</font>, <font color="#2040a0">ierr</font><font color="4444FF">)</font>
<a name="line63"> 63</a>       <font color="#2040a0">mpi_comm</font> <font color="4444FF">=</font> <font color="#2040a0">MPI_COMM_WORLD</font>
<a name="line64"> 64</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_MPICommunicator_CreateF_f</font><font color="4444FF">(</font> <font color="#2040a0">mpi_comm</font>, <font color="#2040a0">bHYPRE_mpicomm</font>,
<a name="line65"> 65</a>      <font color="#FF0000">1</font>      <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line66"> 66</a> 
<a name="line67"> 67</a> <font color="#444444">c   Default problem parameters</font>
<a name="line68"> 68</a>       <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#FF0000">33</font>
<a name="line69"> 69</a>       <font color="#2040a0">solver_id</font> <font color="4444FF">=</font> <font color="#FF0000">0</font>
<a name="line70"> 70</a>       <font color="#2040a0">print_solution</font>  <font color="4444FF">=</font> <font color="#FF0000">0</font>
<a name="line71"> 71</a>       <font color="#2040a0">tol</font> <font color="4444FF">=</font> <font color="#FF0000">1.0d-7</font>
<a name="line72"> 72</a> 
<a name="line73"> 73</a> <font color="#444444">c   The input section not implemented yet.</font>
<a name="line74"> 74</a> 
<a name="line75"> 75</a> <font color="#444444">c   Preliminaries: want at least one processor per row</font>
<a name="line76"> 76</a>       <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">n</font><font color="4444FF">*</font><font color="#2040a0">n</font> .<font color="#2040a0">lt</font>. <font color="#2040a0">num_procs</font><font color="4444FF">)</font> <strong>then</strong>
<a name="line77"> 77</a>          <font color="#2040a0">n</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#2040a0">sqrt</font><font color="4444FF">(</font><strong>real</strong><font color="4444FF">(</font><font color="#2040a0">num_procs</font><font color="4444FF">)</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line78"> 78</a>       <strong>endif</strong>
<a name="line79"> 79</a> <font color="#444444">c     ng = global no. rows, h = mesh size      </font>
<a name="line80"> 80</a>       <font color="#2040a0">ng</font> <font color="4444FF">=</font> <font color="#2040a0">n</font><font color="4444FF">*</font><font color="#2040a0">n</font>
<a name="line81"> 81</a>       <font color="#2040a0">h</font> <font color="4444FF">=</font> <font color="#FF0000">1.0d0</font>/<font color="4444FF">(</font><font color="#2040a0">n</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font>
<a name="line82"> 82</a>       <font color="#2040a0">h2</font> <font color="4444FF">=</font> <font color="#2040a0">h</font><font color="4444FF">*</font><font color="#2040a0">h</font>
<a name="line83"> 83</a> 
<a name="line84"> 84</a> <font color="#444444">c     Each processor knows only of its own rows - the range is denoted by ilower</font>
<a name="line85"> 85</a> <font color="#444444">c     and upper.  Here we partition the rows. We account for the fact that</font>
<a name="line86"> 86</a> <font color="#444444">c     N may not divide evenly by the number of processors.</font>
<a name="line87"> 87</a>       <font color="#2040a0">local_size</font> <font color="4444FF">=</font> <font color="#2040a0">ng</font>/<font color="#2040a0">num_procs</font>
<a name="line88"> 88</a>       <font color="#2040a0">extra</font> <font color="4444FF">=</font> <font color="#2040a0">ng</font> <font color="4444FF">-</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="#2040a0">num_procs</font>
<a name="line89"> 89</a> 
<a name="line90"> 90</a>       <font color="#2040a0">ilower</font> <font color="4444FF">=</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="#2040a0">myid</font>
<a name="line91"> 91</a>       <font color="#2040a0">ilower</font> <font color="4444FF">=</font> <font color="#2040a0">ilower</font> <font color="4444FF">+</font> <font color="#2040a0">min</font><font color="4444FF">(</font><font color="#2040a0">myid</font>, <font color="#2040a0">extra</font><font color="4444FF">)</font>
<a name="line92"> 92</a> 
<a name="line93"> 93</a>       <font color="#2040a0">iupper</font> <font color="4444FF">=</font> <font color="#2040a0">local_size</font><font color="4444FF">*</font><font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font>
<a name="line94"> 94</a>       <font color="#2040a0">iupper</font> <font color="4444FF">=</font> <font color="#2040a0">iupper</font> <font color="4444FF">+</font> <font color="#2040a0">min</font><font color="4444FF">(</font><font color="#2040a0">myid</font><font color="4444FF">+</font><font color="#FF0000">1</font>, <font color="#2040a0">extra</font><font color="4444FF">)</font>
<a name="line95"> 95</a>       <font color="#2040a0">iupper</font> <font color="4444FF">=</font> <font color="#2040a0">iupper</font> <font color="4444FF">-</font> <font color="#FF0000">1</font>
<a name="line96"> 96</a> 
<a name="line97"> 97</a> <font color="#444444">c     How many rows do I have?</font>
<a name="line98"> 98</a>       <font color="#2040a0">local_size</font> <font color="4444FF">=</font> <font color="#2040a0">iupper</font> <font color="4444FF">-</font> <font color="#2040a0">ilower</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line99"> 99</a> 
<a name="line100">100</a> <font color="#444444">c     Create the matrix.</font>
<a name="line101">101</a> <font color="#444444">c     Note that this is a square matrix, so we indicate the row partition</font>
<a name="line102">102</a> <font color="#444444">c     size twice (since number of rows = number of cols)</font>
<a name="line103">103</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRMatrix_Create_f</font><font color="4444FF">(</font> <font color="#2040a0">bHYPRE_mpicomm</font>, <font color="#2040a0">ilower</font>,
<a name="line104">104</a>      <font color="#FF0000">1</font>     <font color="#2040a0">iupper</font>, <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line105">105</a> 
<a name="line106">106</a> <font color="#444444">c     op_A will be needed later as a function argument</font>
<a name="line107">107</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Operator__cast_f</font><font color="4444FF">(</font> <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">op_A</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line108">108</a> 
<a name="line109">109</a> <font color="#444444">c     Choose a parallel csr format storage (see the User's Manual)</font>
<a name="line110">110</a> <font color="#444444">c     Note: Here the HYPRE interface requires a SetObjectType call.</font>
<a name="line111">111</a> <font color="#444444">c     I am using the bHYPRE interface in a way which does not because</font>
<a name="line112">112</a> <font color="#444444">c     the object type is already specified through the class name.</font>
<a name="line113">113</a> 
<a name="line114">114</a> <font color="#444444">c     Initialize before setting coefficients</font>
<a name="line115">115</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRMatrix_Initialize_f</font><font color="4444FF">(</font> <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">ierrtmp</font>,
<a name="line116">116</a>      <font color="#FF0000">1</font>     <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line117">117</a> 
<a name="line118">118</a> <font color="#444444">c     Now go through my local rows and set the matrix entries.</font>
<a name="line119">119</a> <font color="#444444">c     Each row has at most 5 entries. For example, if n=3:</font>
<a name="line120">120</a> <font color="#444444">c</font>
<a name="line121">121</a> <font color="#444444">c      A = [M -I 0; -I M -I; 0 -I M]</font>
<a name="line122">122</a> <font color="#444444">c      M = [4 -1 0; -1 4 -1; 0 -1 4]</font>
<a name="line123">123</a> <font color="#444444">c</font>
<a name="line124">124</a> <font color="#444444">c     Note that here we are setting one row at a time, though</font>
<a name="line125">125</a> <font color="#444444">c     one could set all the rows together (see the User's Manual).</font>
<a name="line126">126</a> 
<a name="line127">127</a>       <strong>do</strong> <font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>
<a name="line128">128</a>          <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#FF0000">1</font>
<a name="line129">129</a> 
<a name="line130">130</a> <font color="#444444">c        The left identity block:position i-n</font>
<a name="line131">131</a>          <strong>if</strong> <font color="4444FF">(</font> <font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">-</font><font color="#2040a0">n</font><font color="4444FF">)</font> .<font color="#2040a0">ge</font>. <font color="#FF0000">0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line132">132</a> 	    <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">-</font><font color="#2040a0">n</font>
<a name="line133">133</a> 	    <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0d0</font>
<a name="line134">134</a> 	    <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#2040a0">nnz</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line135">135</a>          <strong>endif</strong>
<a name="line136">136</a> 
<a name="line137">137</a> <font color="#444444">c         The left -1: position i-1</font>
<a name="line138">138</a>          <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">mod</font><font color="4444FF">(</font><font color="#2040a0">i</font>,<font color="#2040a0">n</font><font color="4444FF">)</font>.<font color="#2040a0">ne</font><font color="#FF0000">.0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line139">139</a>             <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">-</font><font color="#FF0000">1</font>
<a name="line140">140</a>             <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0d0</font>
<a name="line141">141</a>             <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#2040a0">nnz</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line142">142</a>          <strong>endif</strong>
<a name="line143">143</a> 
<a name="line144">144</a> <font color="#444444">c        Set the diagonal: position i</font>
<a name="line145">145</a>          <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">i</font>
<a name="line146">146</a>          <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#FF0000">4.0d0</font>
<a name="line147">147</a>          <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#2040a0">nnz</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line148">148</a> 
<a name="line149">149</a> <font color="#444444">c        The right -1: position i+1</font>
<a name="line150">150</a>          <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">mod</font><font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">)</font>,<font color="#2040a0">n</font><font color="4444FF">)</font> .<font color="#2040a0">ne</font>. <font color="#FF0000">0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line151">151</a>             <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="#FF0000">1</font>
<a name="line152">152</a>             <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0d0</font>
<a name="line153">153</a>             <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#2040a0">nnz</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line154">154</a>          <strong>endif</strong>
<a name="line155">155</a> 
<a name="line156">156</a> <font color="#444444">c        The right identity block:position i+n</font>
<a name="line157">157</a>          <strong>if</strong> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">+</font><font color="#2040a0">n</font><font color="4444FF">)</font> .<font color="#2040a0">lt</font>. <font color="#2040a0">ng</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line158">158</a>             <font color="#2040a0">cols</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">i</font><font color="4444FF">+</font><font color="#2040a0">n</font>
<a name="line159">159</a>             <font color="#2040a0">values</font><font color="4444FF">(</font><font color="#2040a0">nnz</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1.0d0</font>
<a name="line160">160</a>             <font color="#2040a0">nnz</font> <font color="4444FF">=</font> <font color="#2040a0">nnz</font> <font color="4444FF">+</font> <font color="#FF0000">1</font>
<a name="line161">161</a>          <strong>endif</strong>
<a name="line162">162</a> 
<a name="line163">163</a> <font color="#444444">c        Set the values for row i</font>
<a name="line164">164</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRMatrix_SetValues_f</font><font color="4444FF">(</font>
<a name="line165">165</a>      <font color="#FF0000">1</font>        <font color="#2040a0">parcsr_A</font>, <font color="#FF0000">1</font>, <font color="#2040a0">nnz</font><font color="4444FF">-</font><font color="#FF0000">1</font>, <font color="#2040a0">i</font>, <font color="#2040a0">cols</font>, <font color="#2040a0">values</font>, <font color="#FF0000">5</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line166">166</a> 
<a name="line167">167</a>       <font color="#2040a0">enddo</font>
<a name="line168">168</a> 
<a name="line169">169</a> 
<a name="line170">170</a> <font color="#444444">c     Assemble after setting the coefficients</font>
<a name="line171">171</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRMatrix_Assemble_f</font><font color="4444FF">(</font> <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line172">172</a> 
<a name="line173">173</a> <font color="#444444">c     Create the rhs and solution</font>
<a name="line174">174</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Create_f</font><font color="4444FF">(</font> <font color="#2040a0">bHYPRE_mpicomm</font>,
<a name="line175">175</a>      <font color="#FF0000">1</font>     <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">par_b</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line176">176</a> <font color="#444444">c     vec_b will be needed later for function arguments</font>
<a name="line177">177</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Vector__cast_f</font><font color="4444FF">(</font> <font color="#2040a0">par_b</font>, <font color="#2040a0">vec_b</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line178">178</a> 
<a name="line179">179</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Initialize_f</font><font color="4444FF">(</font> <font color="#2040a0">par_b</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line180">180</a> 
<a name="line181">181</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Create_f</font><font color="4444FF">(</font> <font color="#2040a0">bHYPRE_mpicomm</font>,
<a name="line182">182</a>      <font color="#FF0000">1</font>     <font color="#2040a0">ilower</font>, <font color="#2040a0">iupper</font>, <font color="#2040a0">par_x</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line183">183</a> <font color="#444444">c     vec_x will be needed later for function arguments</font>
<a name="line184">184</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Vector__cast_f</font><font color="4444FF">(</font> <font color="#2040a0">par_x</font>, <font color="#2040a0">vec_x</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line185">185</a> 
<a name="line186">186</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Initialize_f</font><font color="4444FF">(</font> <font color="#2040a0">par_x</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line187">187</a> 
<a name="line188">188</a> <font color="#444444">c     Set the rhs values to h^2 and the solution to zero</font>
<a name="line189">189</a>       <strong>do</strong> <font color="#2040a0">i</font> <font color="4444FF">=</font> <font color="#FF0000">1</font>, <font color="#2040a0">local_size</font>
<a name="line190">190</a>          <font color="#2040a0">rhs_values</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">h2</font>
<a name="line191">191</a>          <font color="#2040a0">x_values</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font>
<a name="line192">192</a>          <font color="#2040a0">rows</font><font color="4444FF">(</font><font color="#2040a0">i</font><font color="4444FF">)</font> <font color="4444FF">=</font> <font color="#2040a0">ilower</font> <font color="4444FF">+</font> <font color="#2040a0">i</font> <font color="4444FF">-</font><font color="#FF0000">1</font>
<a name="line193">193</a>       <font color="#2040a0">enddo</font>
<a name="line194">194</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_SetValues_f</font><font color="4444FF">(</font>
<a name="line195">195</a>      <font color="#FF0000">1</font>     <font color="#2040a0">par_b</font>, <font color="#2040a0">local_size</font>, <font color="#2040a0">rows</font>, <font color="#2040a0">rhs_values</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line196">196</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_SetValues_f</font><font color="4444FF">(</font>
<a name="line197">197</a>      <font color="#FF0000">1</font>     <font color="#2040a0">par_x</font>, <font color="#2040a0">local_size</font>, <font color="#2040a0">rows</font>, <font color="#2040a0">x_values</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line198">198</a> 
<a name="line199">199</a> 
<a name="line200">200</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Assemble_f</font><font color="4444FF">(</font> <font color="#2040a0">par_b</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line201">201</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Assemble_f</font><font color="4444FF">(</font> <font color="#2040a0">par_x</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line202">202</a> 
<a name="line203">203</a> <font color="#444444">c     Choose a solver and solve the system</font>
<a name="line204">204</a> 
<a name="line205">205</a> <font color="#444444">c      AMG</font>
<a name="line206">206</a>       <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">solver_id</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line207">207</a> 
<a name="line208">208</a> <font color="#444444">c        Create solver</font>
<a name="line209">209</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_Create_f</font><font color="4444FF">(</font>
<a name="line210">210</a>      <font color="#FF0000">1</font>        <font color="#2040a0">bHYPRE_mpicomm</font>, <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">amg_solver</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line211">211</a> 
<a name="line212">212</a> <font color="#444444">c        Set some parameters (See Reference Manual for more parameters)</font>
<a name="line213">213</a> <font color="#444444">c        PrintLevel=3 means print solve info + parameters</font>
<a name="line214">214</a> <font color="#444444">c        CoarsenType=6 means Falgout coarsening</font>
<a name="line215">215</a> <font color="#444444">c        RelaxType=3 means Gauss-Seidel/Jacobi hybrid relaxation</font>
<a name="line216">216</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetIntParameter_f</font><font color="4444FF">(</font>
<a name="line217">217</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;PrintLevel&quot;</font>, <font color="#FF0000">3</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line218">218</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetIntParameter_f</font><font color="4444FF">(</font>
<a name="line219">219</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;CoarsenType&quot;</font>, <font color="#FF0000">6</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line220">220</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetIntParameter_f</font><font color="4444FF">(</font>
<a name="line221">221</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;RelaxType&quot;</font>, <font color="#FF0000">3</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line222">222</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetIntParameter_f</font><font color="4444FF">(</font>
<a name="line223">223</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;NumSweeps&quot;</font>, <font color="#FF0000">1</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line224">224</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetIntParameter_f</font><font color="4444FF">(</font>
<a name="line225">225</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;MaxLevels&quot;</font>, <font color="#FF0000">20</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line226">226</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_SetDoubleParameter_f</font><font color="4444FF">(</font>
<a name="line227">227</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;Tolerance&quot;</font>, <font color="#2040a0">tol</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line228">228</a> 
<a name="line229">229</a> <font color="#444444">c        Now setup and solve!</font>
<a name="line230">230</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_Setup_f</font><font color="4444FF">(</font>
<a name="line231">231</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#2040a0">vec_b</font>, <font color="#2040a0">vec_x</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line232">232</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_Apply_f</font><font color="4444FF">(</font>
<a name="line233">233</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#2040a0">vec_b</font>, <font color="#2040a0">vec_x</font>, <font color="#2040a0">ierrtmp</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line234">234</a> 
<a name="line235">235</a> <font color="#444444">c        Run info - needed logging turned on </font>
<a name="line236">236</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_GetIntValue_f</font><font color="4444FF">(</font>
<a name="line237">237</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;NumIterations&quot;</font>, <font color="#2040a0">num_iterations</font>, <font color="#2040a0">ierrtmp</font>,
<a name="line238">238</a>      <font color="#FF0000">2</font>        <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line239">239</a>          <font color="#2040a0">ierr</font> <font color="4444FF">=</font> <font color="#2040a0">ierr</font> <font color="4444FF">+</font> <font color="#2040a0">ierrtmp</font>
<a name="line240">240</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_GetDoubleValue_f</font><font color="4444FF">(</font>
<a name="line241">241</a>      <font color="#FF0000">1</font>        <font color="#2040a0">amg_solver</font>, <font color="#008000">&quot;RelResidualNorm&quot;</font>, <font color="#2040a0">final_res_norm</font>, <font color="#2040a0">ierrtmp</font>,
<a name="line242">242</a>      <font color="#FF0000">2</font>        <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line243">243</a> 
<a name="line244">244</a>       <strong>if</strong> <font color="4444FF">(</font><font color="#2040a0">myid</font> .<font color="#2040a0">eq</font>. <font color="#FF0000">0</font><font color="4444FF">)</font> <strong>then</strong>
<a name="line245">245</a>          <strong>print</strong> <font color="4444FF">*</font>
<a name="line246">246</a>          <strong>print</strong> <font color="4444FF">*</font>, <font color="#008000">&quot;Iterations = &quot;</font>, <font color="#2040a0">num_iterations</font>
<a name="line247">247</a>          <strong>print</strong> <font color="4444FF">*</font>, <font color="#008000">&quot;Final Relative Residual Norm = &quot;</font>, <font color="#2040a0">final_res_norm</font>
<a name="line248">248</a>          <strong>print</strong> <font color="4444FF">*</font>
<a name="line249">249</a>       <strong>endif</strong>
<a name="line250">250</a> 
<a name="line251">251</a> <font color="#444444">c     Destroy solver</font>
<a name="line252">252</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_BoomerAMG_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">amg_solver</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line253">253</a> 
<a name="line254">254</a>       <strong>endif</strong>
<a name="line255">255</a> 
<a name="line256">256</a> <font color="#444444">c     The calls of other solvers are not implemented yet.</font>
<a name="line257">257</a> 
<a name="line258">258</a> 
<a name="line259">259</a> <font color="#444444">c     Print the solution</font>
<a name="line260">260</a>       <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">print_solution</font> .<font color="#2040a0">ne</font>. <font color="#FF0000">0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line261">261</a>          <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_Print_f</font><font color="4444FF">(</font> <font color="#2040a0">par_x</font>, <font color="#008000">&quot;ij.out.x&quot;</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line262">262</a>       <strong>endif</strong>
<a name="line263">263</a> 
<a name="line264">264</a> <font color="#444444">c     Clean up</font>
<a name="line265">265</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Operator_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">op_A</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line266">266</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Vector_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">vec_b</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line267">267</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_Vector_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">vec_x</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line268">268</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRMatrix_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">parcsr_A</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line269">269</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">par_b</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line270">270</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_IJParCSRVector_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">par_x</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line271">271</a>       <strong>call</strong> <font color="#2040a0">bHYPRE_MPICommunicator_deleteRef_f</font><font color="4444FF">(</font> <font color="#2040a0">bHYPRE_mpicomm</font>, <font color="#2040a0">except</font> <font color="4444FF">)</font>
<a name="line272">272</a> 
<a name="line273">273</a> <font color="#444444">c     We need a multi-language equivalent of hypre_assert.</font>
<a name="line274">274</a>       <strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">ierr</font> .<font color="#2040a0">ne</font>. <font color="#FF0000">0</font> <font color="4444FF">)</font> <strong>then</strong>
<a name="line275">275</a>          <strong>print</strong> <font color="4444FF">*</font>
<a name="line276">276</a>          <strong>print</strong> <font color="4444FF">*</font>, <font color="#008000">&quot;***** Bad ierr = &quot;</font>, <font color="#2040a0">ierr</font>
<a name="line277">277</a>          <strong>print</strong> <font color="4444FF">*</font>
<a name="line278">278</a>       <strong>endif</strong>
<a name="line279">279</a> 
<a name="line280">280</a> <font color="#444444">c     Finalize MPI</font>
<a name="line281">281</a>       <strong>call</strong> <font color="#2040a0">MPI_Finalize</font><font color="4444FF">(</font><font color="#2040a0">ierrtmp</font><font color="4444FF">)</font>
<a name="line282">282</a> 
<a name="line283">283</a>       <strong>stop</strong>
<a name="line284">284</a>       <strong>end</strong>

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
